class Solution {
public:
    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
vector<vector<int>> t(r, vector<int>(c));
int i;
int x = mat.size(), y= mat[0].size();
        if(x * y == r * c){
            for(i = 0; i < x* y; i++){
                t[i / c][i % c] = mat[i / y][i % y];   
            }
            return t;
        }
        return mat;
    }
};